import axios from 'axios'

export const getMachines = (skip = 0, limit = 100) => {
  return axios.get(`/machines?skip=${skip}&limit=${limit}`)
}

export const getAvailableMachines = (roomId = null) => {
  let url = '/machines/available/'
  if (roomId) {
    url += `${roomId}`
  }
  return axios.get(url)
}

export const createMachine = (machineData) => {
  return axios.post('/machines', machineData)
}

// 修复机器状态更新API - 状态通过查询参数传递
export const updateMachineStatus = (machineId, status) => {
  return axios.patch(`/machines/${machineId}/status?status=${status}`)
}

/**
 * 更新机器信息
 * @param {number} machineId - 机器ID
 * @param {Object} machineData - 机器信息
 * @returns {Promise}
 */
export const updateMachine = (machineId, machineData) => {
  return axios.patch(`/machines/${machineId}`, machineData)
}

/**
 * 获取单个机器详情
 * @param {number} machineId - 机器ID
 * @returns {Promise}
 */
export const getMachineById = (machineId) => {
  return axios.get(`/machines/${machineId}`)
}
